// pages/results/results.js
var app = getApp();
Page({
  data: {
    index:0,
    totalScore: null, // 分数
    wrongList: [], // 错误的题数
    chooseValue: [], // 选择的答案
    testId:"asy",
    questionList:[],
  },
  onLoad: function (options) {
    console.log(options);
    wx.setNavigationBarTitle({ title: options.testId }) // 动态设置导航条标题
    let wrongList = options.wrongList;
    let chooseValue = options.chooseValue;
    let testId = options.testId;
    this.setData({
      totalScore: options.totalScore,
      wrongList: wrongList,
      chooseValue: chooseValue,
      testId: testId
    })
    let that=this
    wx.cloud.database().collection("testList").where({testId:that.data.testId}).get({
      success(res){
        console.log(res.data)
        that.setData({
          questionList:res.data
        })
        console.log(that.data.questionList)
      }
    })
  },
  onShow:function()
  {
  },
  // 返回首页
  toIndex: function () {
    wx.redirectTo({
      url: '../myStudy/myStudy',
    })
  },
  previous()
  {
    if (this.data.index > 0) {
    this.setData({
      index: this.data.index - 1
    })
  }
  },
  nextSubmit()
  {
    if (this.data.index < this.data.questionList.length - 1) {
      // 渲染下一题
      this.setData({
        index: this.data.index + 1
      })
    }
    else
    {
      wx.redirectTo({
        url: '../myStudy/myStudy',
      })
    }
  },
})